#include <iostream>
#include <vector>
#include "MoteCollection.h"
#include "EventManager.h"

using namespace std;

int guess = 0;

void Add(void *arg, Mote *m)
{
	printf("i am %d ", m->GetId());
	if(guess < 100)
	{
		guess++;
	}
	
	printf("%d\n", guess);
	usleep(750000);
}

void Sub(void *arg, Mote *m)
{
	printf("i am %d ", m->GetId());
	if(guess > 0)
	{
		guess--;
	}
	
	printf("%d\n", guess);
	usleep(750000);
}

int main(int argc, char **argv)
{
	MoteCollection *motes = new MoteCollection();
	MoteBridge bridge(motes);
	EventManager *e = new EventManager(&motes);

	int Code = rand() % 100 +1;

	e->RegisterEvent(-1, 10, EXACT, DARK, 5, &Add, NULL);
	e->RegisterEvent(-1, 11, EXACT, DARK, 5, &Sub, NULL);

	cout << "Guess the code (1 ~ 100), press any key to check code." << endl;

	while(true)
	{
		scanf("%*c");
		if(guess == Code)
		{
			cout << "correct!!" << endl;
			break;
		}
		else
		{
			if(guess > Code)
			{
				cout << "lower" << endl;
			}
			else
			{
				cout << "Higher" << endl;
			}
		}
	}
}
